package com.banana.manager.forest.service.impl.handle;

import com.banana.manager.forest.dao.handle.IAreaDao;
import com.banana.manager.forest.dao.handle.IClassDao;
import com.banana.manager.forest.entity.handle.AreaBean;
import com.banana.manager.forest.entity.handle.ClassBean;
import com.banana.manager.forest.service.iihandle.IClassService;
import com.banana.manager.forest.util.PageInfoSize;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class ClassServiceImpl implements IClassService {

    @Resource
    private IAreaDao areaDao;



    @Resource
    private IClassDao classDao;

    /**
     * 此处主要要传入选取的区域
     * @param classBean
     * @param areaId
     * @return
     */

    @Override
    public ClassBean addClass(ClassBean classBean, Integer areaId) {
        classDao.insert(classBean);
        areaDao.updateNewClass(classBean.getClassId(),areaId);
        return classBean;
    }

    /**
     * 以下都是以areabean为主导，导入的时候其实显示的areabean
     * @param
     * @return
     */

    @Override
    public AreaBean findOneById(Integer areaId) {
        return areaDao.findOneIncludeClass(areaId);
    }

    @Override
    public PageInfo<AreaBean> findBlurByPage(Integer page, String className, String areaName) {
        String classNameNew = "%"+className+"%";
        String areaNameNew = "%"+areaName+"%";
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(areaDao.getClassByNameAndArea(areaNameNew,classNameNew));
    }


    @Override
    public ClassBean updateClass(ClassBean classBean) {
        classDao.updateById(classBean);
        return classBean;
    }

    @Override
    public List<ClassBean> showAllClass() {
        return classDao.selectList(null);
    }
}
